package com.sugar.queryinfo.module.business.controller.admin.data.dataquerytanzc;

import com.sugar.queryinfo.module.business.controller.admin.data.dataquerytanzc.vo.DataQueryTanzcPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataquerytanzc.vo.DataQueryTanzcRespVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataquerytanzc.vo.DataQueryTanzcSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.queryinfo.framework.common.pojo.PageParam;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.pojo.CommonResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;
import static com.sugar.queryinfo.framework.common.pojo.CommonResult.success;

import com.sugar.queryinfo.framework.excel.core.util.ExcelUtils;

import com.sugar.queryinfo.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.queryinfo.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.queryinfo.module.business.dal.dataobject.dataquerytanzc.DataQueryTanzcDO;
import com.sugar.queryinfo.module.business.service.dataquerytanzc.DataQueryTanzcService;

@Tag(name = "管理后台 - 数据查询-探针C")
@RestController
@RequestMapping("/business/data-query-tanzc")
@Validated
public class DataQueryTanzcController {

    @Resource
    private DataQueryTanzcService dataQueryTanzcService;

    @PostMapping("/create")
    @Operation(summary = "创建数据查询-探针C")
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:create')")
    public CommonResult<Long> createDataQueryTanzc(@Valid @RequestBody DataQueryTanzcSaveReqVO createReqVO) {
        return success(dataQueryTanzcService.createDataQueryTanzc(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据查询-探针C")
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:update')")
    public CommonResult<Boolean> updateDataQueryTanzc(@Valid @RequestBody DataQueryTanzcSaveReqVO updateReqVO) {
        dataQueryTanzcService.updateDataQueryTanzc(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据查询-探针C")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:delete')")
    public CommonResult<Boolean> deleteDataQueryTanzc(@RequestParam("id") Long id) {
        dataQueryTanzcService.deleteDataQueryTanzc(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除数据查询-探针C")
                //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:delete')")
    public CommonResult<Boolean> deleteDataQueryTanzcList(@RequestParam("ids") List<Long> ids) {
        dataQueryTanzcService.deleteDataQueryTanzcListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据查询-探针C")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:query')")
    public CommonResult<DataQueryTanzcRespVO> getDataQueryTanzc(@RequestParam("id") Long id) {
        DataQueryTanzcDO dataQueryTanzc = dataQueryTanzcService.getDataQueryTanzc(id);
        return success(BeanUtils.toBean(dataQueryTanzc, DataQueryTanzcRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据查询-探针C分页")
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:query')")
    public CommonResult<PageResult<DataQueryTanzcRespVO>> getDataQueryTanzcPage(@Valid DataQueryTanzcPageReqVO pageReqVO) {
        PageResult<DataQueryTanzcDO> pageResult = dataQueryTanzcService.getDataQueryTanzcPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataQueryTanzcRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据查询-探针C Excel")
    //@PreAuthorize("@ss.hasPermission('business:data-query-tanzc:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDataQueryTanzcExcel(@Valid DataQueryTanzcPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DataQueryTanzcDO> list = dataQueryTanzcService.getDataQueryTanzcPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数据查询-探针C.xls", "数据", DataQueryTanzcRespVO.class,
                        BeanUtils.toBean(list, DataQueryTanzcRespVO.class));
    }

}